package com.fw.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.fw.annotation.Log;
import com.fw.core.controller.BaseController;
import com.fw.core.domain.AjaxResult;
import com.fw.enums.BusinessType;
import com.fw.system.admin.domain.TbGuns;
import com.fw.system.admin.service.ITbGunsService;
import com.fw.utils.poi.ExcelUtil;
import com.fw.core.page.TableDataInfo;

/**
 * 装备商品Controller
 * 
 * @author xxx
 * @date 2021-12-03
 */
@RestController
@RequestMapping("/admin/guns")
public class TbGunsController extends BaseController
{
    @Autowired
    private ITbGunsService tbGunsService;

    /**
     * 查询装备商品列表
     */
    @PreAuthorize("@ss.hasPermi('admin:guns:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbGuns tbGuns)
    {
        startPage();
        List<TbGuns> list = tbGunsService.selectTbGunsList(tbGuns);
        return getDataTable(list);
    }

    /**
     * 导出装备商品列表
     */
    @PreAuthorize("@ss.hasPermi('admin:guns:export')")
    @Log(title = "装备商品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbGuns tbGuns)
    {
        List<TbGuns> list = tbGunsService.selectTbGunsList(tbGuns);
        ExcelUtil<TbGuns> util = new ExcelUtil<TbGuns>(TbGuns.class);
        return util.exportExcel(list, "guns");
    }

    /**
     * 获取装备商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:guns:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(tbGunsService.selectTbGunsById(id));
    }

    /**
     * 新增装备商品
     */
    @PreAuthorize("@ss.hasPermi('admin:guns:add')")
    @Log(title = "装备商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbGuns tbGuns)
    {
        return toAjax(tbGunsService.insertTbGuns(tbGuns));
    }

    /**
     * 修改装备商品
     */
    @PreAuthorize("@ss.hasPermi('admin:guns:edit')")
    @Log(title = "装备商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbGuns tbGuns)
    {
        return toAjax(tbGunsService.updateTbGuns(tbGuns));
    }

    /**
     * 删除装备商品
     */
    @PreAuthorize("@ss.hasPermi('admin:guns:remove')")
    @Log(title = "装备商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbGunsService.deleteTbGunsByIds(ids));
    }
}
